<template>
    <div>
         <el-form ref="bookInfo" :model="bookInfo" label-width="100px">
         <el-form-item label="书名">
            <el-input v-model="bookInfo.bookName" class="in" ></el-input>
         </el-form-item>
         <el-form-item label="原书名">
            <el-input placeholder="非必填" v-model="bookInfo.oBookName"  class="in" ></el-input>
         </el-form-item>
        <el-form-item label="图片链接">
            <el-input v-model="bookInfo.imgUrl" class="in" >  
            </el-input>
        </el-form-item>
        <el-form-item label="作者">
            <el-input v-model="bookInfo.author" class="in" >  
            </el-input>
        </el-form-item>
        <el-form-item label="出版社">
            <el-input placeholder="非必填" v-model="bookInfo.press" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="出品方">
              <el-input placeholder="非必填" v-model="bookInfo.product" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="出版日期">
              <el-input placeholder="非必填" v-model="bookInfo.birthday" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="ISBN">
              <el-input  v-model="bookInfo.ISBN" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="价格">
              <el-input  v-model="bookInfo.price" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="页数">
              <el-input  v-model="bookInfo.pageNumber" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="副标题">
              <el-input placeholder="非必填"  v-model="bookInfo.subtitle" class="in" > 
            </el-input>
        </el-form-item>
         <el-form-item label="丛书">
              <el-input placeholder="非必填"  v-model="bookInfo.series" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="类型">
              <el-input  v-model="bookInfo.type" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="译者">
              <el-input placeholder="非必填"  v-model="bookInfo.tarnslator" class="in" > 
            </el-input>
        </el-form-item>
        <el-form-item label="装帧">
              <el-input placeholder="非必填"  v-model="bookInfo.dreUp" class="in" > 
            </el-input>
        </el-form-item>
          <el-form-item label="库存">
              <el-input   v-model.number="bookInfo.sum" class="in" > 
            </el-input>
        </el-form-item>
        
        <el-form-item>
            <el-button type="primary"  @click="onSubmit">立即添加</el-button>
            <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>
<script>
export default {
    data(){
        return{
            bookInfo:{
                bookName:"",
                oBookName:"",
                imgUrl:"",
                author:"",
                press:"",
                product:"",
                birthday:"",
                ISBN:"",
                price:"",
                series:"",
                tarnslator:"",
                subtitle:"",
                type:"",
                sum:"",
                dreUp:"",
                pageNumber:""


            }
        }
    },
    methods:{
      async  onSubmit(){
        const result = await this.$axios.put('/api/admin/addBook',{
            book:this.bookInfo
        });
      if( result !==null){
         this.$message({
                      showClose: true,
                      message: '添加成功！',
                      type: 'success'
                });
          this.$router.push("/about");

       }else{
         this.$message({
                      showClose: true,
                      message: '添加失败！',
                      type: 'error'
                });
       }
      },
      cancel(){
          this.$router.push("/about");
      }
    }
}
</script>